<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ page import="com.google.appengine.api.users.User" %>
<%@ page import="com.google.appengine.api.users.UserService" %>
<%@ page import="com.google.appengine.api.users.UserServiceFactory" %>
<%@ page import="javax.jdo.PersistenceManager" %>
<%@ page import="javax.jdo.Query" %>
<%@ page import="java.util.List" %>
<%@ page import="member.*" %>
<%@ page import="shared.PMF" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>會員資料</title>

<style type="text/css">

.tablein {
	font-size: 36px;
	color: #CCC;
	background-color: #000;
}

.hot {
	font-size: 12px;
	font-weight: bolder;
	text-transform: capitalize;
	color: #F00;
	text-decoration: underline;
}


.title {
	font-size: 70px;
	font-weight: bolder;
	color: #000;
}
a {text-decoration: none;
	 color: #000;
} 

.tableins {
	font-size: 36px;
	color: #CCC;
	background-color: #000;
	color: #CC3333;
}


.tabletits {
	font-size: xx-large;
	color: #009;
}
.tabletit {
	font-size: 36px;
	color: #000;
	border-top-color: #000;
	border-right-color: #000;
	border-bottom-color: #000;
	border-left-color: #000;
	text-decoration: none;
}
body {
	background-color: #99C;
}
.tableCon {
	color: #00F;
	text-decoration: underline;
}
</style>
</head>
<body>

<table border="1">
<%
	UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
    String userName = "";
    boolean intiLogin = true;
    if (user != null) {
    	userName = user.getNickname();
    %>

    <p>	<a href="<%= userService.createLogoutURL(request.getRequestURI()) %>">
    <p><a href="<%= userService.createLogoutURL(request.getRequestURI()) %>"><span class ="hot" >登出</span></a></p>

	<%
	//如果不是會員，將帳號儲存
		PersistenceManager pm = PMF.get().getPersistenceManager();
		Query query = pm.newQuery(Member.class);
		query.setFilter("transTimes >= 0");
		try {
		    List<Member> results = (List<Member>) query.execute();
		    if (!results.isEmpty()) {
		        for (Member p : results) {
					if(userName.equals(p.getName())){
						intiLogin = false;
						%>
						<td>會員姓名</td><td>會員暱稱</td><td>會員評分</td><td>交易次數</td><td>交易點數量</td><td>修改暱稱</td></tr>
						<tr>
						<td><%=p.getName() %></td>
						<td><%=p.getNickName() %></td>
						<td><%=p.getScore() %></td>
						<td><%=p.getTransTimes() %></td>
						<td><%=p.getPoint() %></td>
						
						<td><form action="/mem/editMem02.jsp" method="get">
						<input type="hidden" name="id" value="<%=p.getId() %>">
						<input type="hidden" name="nickName" value="<%=p.getNickName() %>">
						<input type="submit" value="修改" />
						</form></td>
						</tr>
						</table>
						<%
						break;
					}
		        }// for
		    }else{
		    	out.println("無會員資料!");
		    }   
		}finally {
		        query.closeAll();
		        pm.close();
		}
		if(intiLogin == true){
	    	response.sendRedirect("../test.jsp");
	    }
    } else {
	%>
		<p>請
		<a href="<%= userService.createLoginURL(request.getRequestURI()) %>">登入</a>,
		以便開始點數交換</p>
	<%
    }
	%>
</table>

<a href="../index_un.jsp">回到首頁</a>
</body>
</html>